# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libtommath
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=1
pkgdesc="Highly optimized and portable routines for integer based number theoretic applications (mingw-w64)"
url="http://www.libtom.org/"
arch=('any')
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/libtom/libtommath/archive/v${pkgver}.tar.gz)
sha256sums=('f3c20ab5df600d8d89e054d096c116417197827d12732e678525667aa724e30f')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  sed -i "s/VERSION_SO)/VERSION_SO) -no-undefined/" makefile.shared
}

build() {
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  CFLAGS+=" -I${srcdir}/build-${MINGW_CHOST}"
  CC="${MINGW_PREFIX}/bin/gcc" \
  make -f makefile.shared IGNORE_SPEED=1
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}

  CC=${MINGW_PREFIX}/bin/gcc \
  make -f makefile.shared mtest
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  CC="${MINGW_PREFIX}/bin/gcc" \
  make -f makefile.shared \
    DESTDIR=${pkgdir} \
    INSTALL_GROUP=root \
    LIBPATH=${MINGW_PREFIX}/lib \
    INCPATH=${MINGW_PREFIX}/include \
    DATAPATH=${MINGW_PREFIX}/share/doc/libtommath/pdf \
    install

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  chmod 644 ${pkgdir}${MINGW_PREFIX}/lib/libtommath{.dll,}.a
}
